home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Technology Seed / ADC Seed CD - July 1999.toast / USB / Mac OS USB DDK v1.2 / Examples / USBSampleStorageDriver / StorageClassUTDriver.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-04-15  |  4.6 KB  |  139 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        StorageClassUTDriver.c
  3.  
  4.     Contains:    This file contains the globally exported symbols and 
  5.                 entry points into the Storage Class UT driver.
  6.  
  7.     Version:    1.1
  8.  
  9.     Copyright:    © 1998-1999 by Apple Computer, Inc., all rights reserved.
  10.  
  11. */
  12.  
  13. #include "StorageClassUTDriver.h"
  14. #include "StorageClassUTFunctions.h"
  15. #include "SampleStorageVersion.h"
  16.  
  17. //----------------------------------------------------------------------------------
  18. //    The Driver Description structure -
  19. //     This structure provides the Device Manager with information about our native driver
  20. //----------------------------------------------------------------------------------
  21.  
  22. DriverDescription TheDriverDescription = 
  23. {
  24.     kTheDescriptionSignature,
  25.     kInitialDriverDescriptor,
  26.  
  27.     // DriverType
  28.     "\p.StorageClass_UT_Driver",
  29.     kStorageHexMajorVers, kStorageHexMinorVers, kStorageReleaseStage, kStorageCurrentRelease,
  30.  
  31.     // DriverOSRuntimeInfo
  32.     0
  33.     | (1 * kDriverIsLoadedUponDiscovery)    //    Loader runtime options
  34.     | (1 * kDriverIsOpenedUponLoad)            //    Opened when loaded
  35.     | (0 * kDriverIsUnderExpertControl)        //    No I/O expert to handle loads/opens
  36.     | (0 * kDriverIsConcurrent)                //    Not concurrent yet
  37.     | (0 * kDriverQueuesIOPB),                //    Not internally queued yet
  38.     "\p.StorageClass_UT_Driver",                    //    Str31 driverName (OpenDriver param)
  39.     0, 0, 0, 0, 0, 0, 0, 0,                    //    UInt32 driverDescReserved[8]
  40.  
  41.     // DriverOSService
  42.     1,                                        //    ServiceCount nServices
  43.  
  44.     // DriverServiceInfo
  45.     kServiceCategoryNdrvDriver,                //    OSType serviceCategory
  46.     kNdrvTypeIsGeneric,                        //    OSType serviceType
  47.     kStorageHexMajorVers, kStorageHexMinorVers, kStorageReleaseStage, kStorageCurrentRelease
  48. };
  49.  
  50. //----------------------------------------------------------------------------------
  51. //    The DoDriverIO Function -
  52. //     This function is the only entry to our driver from the Device Manager
  53. //----------------------------------------------------------------------------------
  54.  
  55. OSStatus DoDriverIO(    AddressSpaceID        addressSpaceID,
  56.                         IOCommandID            ioCommandID,
  57.                         IOCommandContents    ioCommandContents,
  58.                         IOCommandCode        ioCommandCode,
  59.                         IOCommandKind        ioCommandKind)
  60. {
  61.     OSStatus    status;
  62.         
  63.     IfDebugging("\pIn my driver");
  64.     /*
  65.         Note: Initialize, Open, KillIO, Close, and Finalize are either synchronous
  66.         or immediate. Read, Write, Control, and Status may be immediate,
  67.         synchronous, or asynchronous.
  68.     */
  69.     switch (ioCommandCode)
  70.     {
  71.         case kInitializeCommand:        /* Always immediate */
  72.             status = DriverInitializeCmd (addressSpaceID, ioCommandContents.initialInfo);
  73.             break;
  74.         case kFinalizeCommand:            /* Always immediate */
  75.             status = DriverFinalizeCmd (ioCommandContents.finalInfo);
  76.             break;
  77.         case kSupersededCommand:        /* Always immediate */
  78.             status = DriverSupersededCmd (ioCommandContents.supersededInfo);
  79.             break;
  80.         case kReplaceCommand:            /* Always immediate, replace an old driver */
  81.             status = DriverReplaceCmd (addressSpaceID, ioCommandContents.replaceInfo);
  82.             break;
  83.         case kOpenCommand:                /* Always immediate */
  84.             status = DriverOpenCmd (addressSpaceID, ioCommandContents.pb);
  85.             break;
  86.         case kCloseCommand:                /* Always immediate */
  87.             status = DriverCloseCmd (ioCommandContents.pb);
  88.             break;
  89.         case kControlCommand:
  90.             status = DriverControlCmd (addressSpaceID, ioCommandID, ioCommandKind, ioCommandContents.pb);
  91.             break;
  92.         case kStatusCommand:
  93.             status = DriverStatusCmd (addressSpaceID, ioCommandID, ioCommandKind, ioCommandContents.pb);
  94.             break;
  95.         case kReadCommand:
  96.             status = DriverReadCmd ( addressSpaceID, ioCommandID, ioCommandKind, ioCommandContents.pb);
  97.             break;
  98.         case kWriteCommand:
  99.             status = DriverWriteCmd ( addressSpaceID, ioCommandID, ioCommandKind, ioCommandContents.pb);
  100.             break;
  101.         case kKillIOCommand:            /* Always immediate */
  102.             status = DriverKillIOCmd (ioCommandContents.pb);
  103.             break;
  104.         default:
  105.             status = paramErr;
  106.             break;
  107.     }
  108.     
  109.     return FinishCommandProcessing(ioCommandID, ioCommandKind, status);
  110. }
  111.     
  112. OSStatus FinishCommandProcessing(IOCommandID ioCommandID,IOCommandKind ioCommandKind,OSStatus incomingStatus)
  113. {
  114.     OSStatus status = incomingStatus;
  115.     
  116.     IfDebugging("\pFinishCommandProcessing");
  117.     
  118.     if ((ioCommandKind & kImmediateIOCommandKind) != 0)
  119.     {
  120.         /* Immediate commands return the operation status and don't call IOCommandIsComplete */
  121.         IfDebugging("\pImmd cmd complete");
  122.     }
  123.     else if (incomingStatus == ioInProgress)
  124.     {
  125.         IfDebugging("\pincomingStatus == ioInProgress");
  126.         /* Perform the action and call IOCommandIsComplete at some later time */
  127.         status = noErr;
  128.     }
  129.     else
  130.     {
  131.         IfDebugging("\pDo Command Is Complete");        
  132.         status = IOCommandIsComplete (ioCommandID, incomingStatus);
  133.     }
  134.  
  135.     IfDebugging("\pExit FinishCommandProcessing");
  136.     return (status);
  137. }
  138.  
  139.